//
//  TestClassA.m
//  MessageForwarding
//
//  Created by 刘博 on 15/4/25.
//  Copyright (c) 2015年 AutoNavi. All rights reserved.
//

#import "TestClassA.h"
#import "TestClassB.h"
#import <objc/runtime.h>

@implementation TestClassA

- (instancetype)init
{
    if (self = [super init])
    {
        
    }
    return self;
}

#pragma mark - Step 1: resolveMethod

Class dynamicAddMethod(id self, SEL _cmd, NSString *aString)
{
    NSLog(@"ClassA: %@", aString);
    
    return [self class];
}

- (Class)dynamicAddMethod:(NSString *)aString
{
    NSLog(@"ClassA: %@", aString);
    
    return [self class];
}

+ (BOOL)resolveInstanceMethod:(SEL)sel
{
    NSLog(@"%s", __func__);
    
    if (sel == @selector(doDynamicAddMethod))
    {
//        IMP dynamicIMP = class_getMethodImplementation([self class], @selector(dynamicAddMethod:));
        
        class_addMethod([self class], sel, (IMP)dynamicAddMethod, "#@:@");
        
        return YES;
    }
    
    return NO;
}

+ (BOOL)resolveClassMethod:(SEL)sel
{
    NSLog(@"%s", __func__);
    
    return NO;
}

@end
